POV-Ray : Newsgroups : povray.text.scene-files : Another Lightning macro : Another Lightning macro Server Time
5 Jul 2024 10:55:08 EDT (-0400)
  Another Lightning macro  
From: Tom Melly
Date: 30 Apr 2001 11:30:11
Message: <3aed8503$1@news.povray.org>
A new trend? The main problem with this macro is that changing one param.
has too great an effect on the behaviour of other params. Oh, and the bolt
is upside down.

// lightning macro w/ sample scene

#version unofficial MegaPov 0.6;
camera{location  <0.0, 0.5, -25.0> look_at   <0.0, 0.0,  0.0>}

//LArraySize = increase this if you get array error messages
//LSeed = random seed for bolt
//LWidth = width of bolt threads
//LHeight = height of whole bolt
//LSpread = spread of bolt
//LBranch = increase for more spikes
//LCutoff = start point for possible forks
//LSpike = increase for a more jagged bolt

#macro Make_Bolt(LArraySize, LSeed, LWidth, LHeight, LSpread, LBranch,
LCutoff, LSpike)

  #declare myArray = array[LArraySize]
  #declare checkCount = -1;
  #declare highCount = 0;
  #declare arrayCount = 0;
  #declare myArray[arrayCount] = <0,0,0>;

  #declare myRand = seed(LSeed);

  #declare Lightning_Bolt =
  merge{
    #while (checkCount < highCount)
      #declare checkCount = checkCount + 1;
      #declare segPosA = myArray[arrayCount];
      #declare arrayCount = arrayCount + 1;
      #declare xPlus = (rand(myRand)-0.5)*LSpread;
      #declare zPlus = (rand(myRand)-0.5)*LSpread;
      #while(segPosA.y < LHeight)
        #declare xShift = segPosA.x + ((rand(myRand)-0.5)*LSpike) + xPlus;
        #declare yShift = segPosA.y + (rand(myRand)/5);
        #declare zShift = segPosA.z + ((rand(myRand)-0.5)*LSpike) + zPlus;
        #if (yShift > LHeight)
          #declare yShift = LHeight;
        #end
        #declare segPosB = <xShift, yShift, zShift>;
        cylinder{segPosA, segPosB, LWidth}
        sphere{segPosB, LWidth + 0.0001}
        #declare segPosA = segPosB;
        #declare randNum = rand(myRand);
        #if (randNum < LBranch & segPosA.y > LCutoff)
          #declare highCount = highCount + 1;
          #declare myArray[highCount] = segPosA;
        #end
      #end
    #end
  }
#end

Make_Bolt(500, 7, 0.05, 6, 0.3, 0.065, 0.5, 0.5)
object{
  Lightning_Bolt
  pigment{rgbf 1}
  interior{media{emission rgb <40,40,50>} media{absorption rgb <50,50,40>}}
hollow on
  rotate x*180
  no_shadow
  translate y*6
}


--
"To stop children being afraid of the dark, try to fill their daylight hours
with as much terror as possible"
www.tomandlu.co.uk


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.